package com.aiyige.page.my.order.dialog;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.model.Subject;
import com.aiyige.page.my.order.model.SubjectSelection;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/10/17.
 */

public class ClassifyAdapter extends BaseQuickAdapter<SubjectSelection, BaseViewHolder> {

    public ClassifyAdapter() {
        super(new LinkedList<SubjectSelection>());
    }

    @Override
    protected void convert(BaseViewHolder helper, SubjectSelection item) {
        ((OrderHolder) helper).bindData(item);
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = new OrderHolder(getItemView(R.layout.item_order_classify, parent));
        return baseViewHolder;
    }

    public class OrderHolder extends BaseViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.iv_selection)
        ImageView ivSelection;

        SubjectSelection entnty;

        public OrderHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }


        public void bindData(SubjectSelection data) {
            entnty = data;
            tvName.setText(Subject.getSubjectName(entnty.getSubject()));
            ivSelection.setImageResource(entnty.isSelected()?R.drawable.order_screen_selected:R.drawable.order_screen_normal);
        }

    }

    public void reset() {
        List<SubjectSelection> list =  getData();
        if (list == null || list.isEmpty()) {
            return;
        }
        for (SubjectSelection goodsType : list) {
            goodsType.setSelected(false);
        }
        notifyDataSetChanged();
    }

}
